package com.config;

import com.alibaba.fastjson.serializer.PropertyFilter;


/**
 * Created by Administrator on 2017/6/19.
 * json序列化过滤，假如是hibernate代理，则不序列化，是lazy生效
 */
public class SimplePropertyFilter
        implements PropertyFilter
{
    @Override
    public boolean apply(Object obj, String s, Object obj1) {
//        if (obj1 instanceof HibernateProxy) {// hibernate代理对象
//            LazyInitializer initializer = ((HibernateProxy) obj1)
//                    .getHibernateLazyInitializer();
//            if (initializer.isUninitialized()) {
//                return false;
//            }
//        } else if (obj1 instanceof PersistentCollection) {// 实体关联一对多
//            PersistentCollection collection = (PersistentCollection) obj1;
//            if (!collection.wasInitialized()) {
//                return false;
//            }
//        }
        return true;
    }
}
